'use strict';


const Service = require('egg').Service;
class OltTypeService extends Service {
  async list(params) {
    return await this.ctx.modelmysql.OltType.findAndCountAll({
      where: {
        tid: params.tid,
      },
      offset: parseInt((params.page - 1) * params.limit),
      limit: parseInt(params.limit),
    });
  }
  async delete(params) {
    await this.ctx.model.OltType.destroy({
      id: params.id,
    });
  }
  async listAll(tid) {
    const result = await this.ctx.modelmysql.OltType.findAll({
      where: {
        tid,
      },
    });
    return result;
  }
  async scriptList(params) {
    return await this.ctx.modelmysql.Script.findAndCountAll({
      where: {
        olttypeId: params.oltTypeId,
      },
      offset: parseInt((params.page - 1) * params.limit),
      limit: parseInt(params.limit),
    });
  }
  async scriptEdit(params) {
    const result = {
      msg: '',
    };
    try {
      await this.ctx.model.Script.update({ script: params.script, MountPoint: params.MountPoint, version: params.version }, { where: { id: params.id } });
      result.msg = 'edit script successful';
      return result;
    } catch (error) {
      result.msg = 'edit script fail,' + error;
      return result;
    }
  }
}


module.exports = OltTypeService;
